<!DOCTYPE html>
<html lang="en" style="height:100%">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>资金密码设置</title>

    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/yzl.css"/>


</head>
<body style="height:100%;">
<div id="blank" class="header">
    <div v-back.tapmode class="back"></div>
    <span class="title">资金密码设置</span>
</div>
<div id="app" v-cloak class="container" style="height:100%" :style="{backgroundColor:bg}">
    <div v-show="isSettled" style="text-align:center;margin-top:140px;">
        <div>
            <img style="width:150px;" v-src="'../../image/withdraw_settled.png'">
        </div>
        <div style="margin-top:45px;">
            <span>资金密码已设置</span>
        </div>
        <div style="margin-top:90px;">
            <a class="btn-commit" v-myclick="forget">忘记密码</a>
        </div>
    </div>
    <div v-show="!isSettled" style="margin-top:60px;">
        <div style="text-align:center">
            <span style="margin:40px auto;text-align:center;font-size:12px;color:#a8a8a8;">点击“发送验证码”我们将向您当前邮箱发送一条验证码</span>
        </div>
        <div class="modifyPwd-row">
            <img v-src="'../../image/modifyPwd_icon_code.png'">
            <input placeholder="请输入验证码" v-model="code">
            <sendcode style="right:10px" :email="email" :type="6"></sendcode>
        </div>
        <div class="modifyPwd-row">
            <img v-src="'../../image/modifyPwd_icon_pwd.png'">
            <input type="password" placeholder="输入新的资金密码" v-model="newPwd" v-show="ifClosed">
            <input type="text" placeholder="输入新的资金密码" v-model="newPwd" v-show="!ifClosed">
            <img class="right" v-src="'../../image/modifyPwd_icon_close.png'" v-show="ifClosed" v-myclick="changeIfClosed" key="close">
            <img class="right" v-src="'../../image/modifyPwd_icon_open.png'" v-show="!ifClosed" v-myclick="changeIfClosed" key="open">
        </div>
        <a class="btn-commit" style="margin-top:50px;" v-myclick="updPassword">提交</a>
    </div>
</div>
</body>
<script src="../../script/api.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/url.js"></script>
<script src="../../script/components.js"></script>
<script>

    var vm;
    var user;

    var withdraw_password_settled;

    apiready = function () {
        setBSImg();
        new Vue({
            el: '#blank'
        });
        user = JSON.parse(getPrefs('user'));
        console.log(JSON.stringify(user));
        withdraw_password_settled = user.withdraw_password_settled;
        initApp();
        api.parseTapmode();
        addListeners();
    };

    function initApp() {
        vm = new Vue({
            el: '#app',
            data: {
                email: user.email,
                code: '',
                newPwd:'',
                ifClosed:true,
                withdraw_password_settled:withdraw_password_settled
            },
            computed:{
                isSettled: function () {
                    return this.withdraw_password_settled == 1;
                },
                text: function () {
                    return this.ifClosed ? 'password' : 'text';
                },
                bg:function () {
                    return this.withdraw_password_settled == 1 ? '#ffffff' : '#f7f7f7'
                }
            },
            methods:{
                updPassword:function () {
                    var data = {
                        member_id : getPrefs('member_id'),
                        email:this.email,
                        verify_code:this.code,
                        password:this.newPwd
                    };
                    var callback = function () {
                        user.withdraw_password_settled = 1;
                        setPrefs('user', user);
                        api.sendEvent({
                            name: 'settleWithdrawPassword'
                        });
                        pinet.alert('修改资金密码成功', closeWin);
                    };
                    pinet.post(URL.setPassword, data, callback);
                },
                forget:function () {
                    this.withdraw_password_settled = 0;
                },
                changeIfClosed: function () {
                    this.ifClosed = !this.ifClosed;
                },
            }
        });
    }

    function addListeners() {
        api.addEventListener({
            name: 'viewappear'
        }, function () {
            onPageStart();
        });

        api.addEventListener({
            name: 'viewdisappear'
        }, function () {
            onPageEnd();
        });

        api.addEventListener({
            name: 'keyback'
        }, function () {
            onPageEnd();
            api.closeWin();
        });
    }

</script>
</html>
